import 'dart:math';

import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/data/request/application_request.dart';
import 'package:bxultimate/domain/home/home_data_dto.dart';
import 'package:get/get.dart';

import 'state.dart';

class ApplicationNewsIndexController extends GetxController {
  final ApplicationNewsIndexState state = ApplicationNewsIndexState();

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();


    state.title = Get.arguments["title"];
    getData(true);
  }

  var pageSize = 10;
  var pid = Get.arguments['id'];

  getData(bool isClear) async {
    state.carouselList = await ApplicationRequest.getBannsArticle(pid);
    state.newsCategory = await ApplicationRequest.getNewsCategory(pid);
    var list =
    await ApplicationRequest.getArticleByType(state.page, pageSize, pid);
    if (isClear) {
      state.articleList = list;
    } else {
      state.articleList.addAll(list);
    }
  }

  Future<void> onRefresh() async {
    state.page = 1;
    await getData(true);
  }

  Future<void> onLoad() async {
    state.page++;
    await getData(false);
  }

  void toArticleDetail(Article article) {
    Get.toNamed(RouterName.articleDetail, arguments: article.id);
  }
}
